/*
 * ParamLong.java
 * 
 * Copyright 2004 Christoph Csallner and Yannis Smaragdakis.
 */
package edu.gatech.cc.cnc.params;

import de.fhg.first.fd.X;
import edu.gatech.cc.jcrasher.plans.expr.Expression;
import edu.gatech.cc.jcrasher.plans.expr.literals.LongLiteral;

/**
 * ParamLong
 * 
 * @author csallner@gatech.edu (Christoph Csallner)
 * @version	$Id: $
 */
public class ParamLong extends ParamIntegral<Long> {

	/**
	 * Constructor
	 * precondition: resetSolver() 
	 */
	public ParamLong(String name) {
		super(
				ParamInt.getDomain().getMin(),
				ParamInt.getDomain().getMax(),
				name,
				ParamInt.getDomain());
	}
	
	
	
	/* @return if long val is within the domain used for int. */
	protected boolean isInDomain(long val) {
		long domMin = (long) ParamInt.getDomain().getMin();
		long domMax = (long) ParamInt.getDomain().getMax();
		
		if (domMin<=val && val<=domMax)
			return true;
		
		return false;
	}
	
	@Override
	public X parse(String constant) {
		long l;
		try {
		 l = Long.parseLong(constant);}
		catch(NumberFormatException e) {
			return parseError(constant);
		}
		
		if (isInDomain(l))
			return solver.newX((int)l);
		
		return tooLargeForSolver(constant);
	}

	
	/**
	 * Assumes that constraint system solution to which var belongs has been
	 * first prepared and then generated before.
	 */	
	@Override
	public Expression<Long> getPlanExpression() {
		return new LongLiteral(getValue());
	}
	
	@Override
	public Class<Long> getType() {
		return Long.TYPE;
	}
}
